package com.peanut.controller;

import com.peanut.common.ResultModel;
import com.peanut.model.User;
import com.peanut.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController  {
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/getUserById",method = RequestMethod.GET)
    public User getUserById(@RequestParam Integer id){
        return userService.getUserById(id);
    }

    @ResponseBody
    @RequestMapping(value = "/addUser",method = RequestMethod.POST)
    public User addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @ResponseBody
    @RequestMapping(value = "/delById",method = RequestMethod.DELETE)
    public User delById(@RequestParam Integer id){
        return userService.delById(id);
    }

    @ResponseBody
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public User update(@RequestBody User user){
        return userService.update(user);
    }

    @ResponseBody
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ResultModel list(){
        ResultModel<Object> objectResultModel = new ResultModel<>();
        List<User> list = userService.list();
        objectResultModel.setObject(list);
        return objectResultModel;
    }





}
